define(function(require, exports, module) {
    var router = require("router");
    //var app = require("app");
    var controller = {};
    controller.vue = function(params) {
        controller.vm = new Vue({
            router: router,
            data: function data() {
                return {
                    user_info: {
                        community:{},
                        tenement_type:[]
                    },
                    items: [],
                    page: 1,
                    lastPage:0,
                    mounted: 0,
                    listData: [],
                    showNoData:0,
                    out_room_id:0,
                    community_id:0,
                    shopUrl:''

                };
            },
            el: "#pageIndex",
            created: function created() {
                // this.getnotification();
                this.getUserInfo();
                this.getrecommend();
                // this.shopUrl = 'https://www.bestsmartbee.com//mall/pages/renderPage?shop_id='+this.$route.params.community_id+'&page=pages%2Findex%2Findex'
            },

          

            mounted: function mounted() {
                    if (this.mounted == 1) {
                        return;
                    }
                    
                    var that = this ;
                    app.pager("#pageIndex",function(){
                      that.getrecommend();
                    });
                    if(this.$route.params.community_id){
                        this.community_id = this.$route.params.community_id;
                    }
                  
                    this.mounted = 1;
            },
            methods: {

              getrecommend() {
              var that = this;
              var page = that.page;
              if ( that.lastpage == 1) {
                return;
              }
              that.loaded = 1;
              //console.log(event_type);
              app.get("sns/topic/list", {
                page: page,
                pid2: 0,
                pid: 100,
                limit: 3,
                order: 'id desc',
              }, function (res) {
               
                if (res.code != 200) {
                  app.alert(res.msg);
                  return;
                }
                if (res.data.list.length > 0) {
                  that.setData({ listData: that.listData.concat(res.data.list) });
                } else {
                  that.lastpage = 1;
                }
                if(that.listData.length===0 ){
                  that.showNoData = 1;
                }else{
                  that.showNoData = 0;
                }
                
                that.loading = 0;
                that.page++;
              });
            },
                getUserInfo:function(){
                  if(this.$route.params.community_id){
                        this.community_id = this.$route.params.community_id;
                    }
                    var that = this;
                    app.get("/api/user/info",{
                        community_id:this.community_id,
                        fields:"user_id,store_id,phone,nickname,phone,avatarUrl,community,community_count,tenement_type,out_room_id"
                    },function(res){
                         if(res.code==200){
                             that.user_info = res.data;
                             if(res.data.out_room_id){
                                that.out_room_id = res.data.out_room_id;
                             }
                             if(res.data.community && res.data.community.name){
                                 that.community_id=res.data.community.id;
                                 app.setTitle(res.data.community.name);
                             }else{
                                 that.changeShopId();
                                // app.alert("当前手机号未绑定小区，请联系物业公司认证业主身份，或发起工单");
                             }
                         }
                        
                    });
                },
                changeShopId:function(){
                    var that = this;
                    app.component("get_shop_id",{
                         title:'请选择小区',
                         type:'tenement',
                         success:function(shop_id){
                             that.$router.push({name:"index",params:{community_id:shop_id}});
                         }
                      });
                },
                 //提醒列表
                  getnotification:function(reload) {
                    if (reload==1){
                      this.setData({
                        loading: 0,
                        page:1,
                        listData:[],
                        lastPage:0
                      });
                    }
                    //通知提醒 
                    var that = this;
                    var page = this.page;
                    this.setData({
                      loading: 1
                    });
                    app.get("api/notification/get", {
                      page: page,
                      status:0,
                      limit: 20,
                    }, function (res) {
                     
                      if (res.code != 200) {
                        app.alert(res.msg);
                        return;
                      }
                      that.setData({ notiCount: res.data.recordsFiltered});
                      //that.delNoit("noti");
                      if (res.data.list.length === 0) {
                        that.setData({
                          lastPage: 1
                        });
                      }

                      page++;
                      if (res.data.list) {
                        that.setData({ page: page, loading: 0, 'listData': that.listData.concat(res.data.list) });
                      }
                      if (that.listData.length===0){
                        that.setData({ showNoData:1});
                      }
                    });
                  },
                  setData:function(data){
                     for(var i in data){

                        this[i]=data[i];
                     }
                  },
                   jumpnoti: function (id) {
                    var that = this;
                    
                    that.listData[id].status = 1;
                    var data = this.listData[id];
                    app.get("api/notification/add", {
                      status: 1,
                      id: data.id,
                      method: 'POST',
                    }, function (res) {
                      that.setData({ listData: that.listData });
                    });

                    // wx.navigateTo({
                    //   url: "/"+data.url
                    // })
                  },
              }
        }).$mount("#app");
    };
    controller.pageShow = function() {};
    module.exports = controller;
});
